Skip to content

Project Euler

When it comes to front-end developer roles, most companies have realized that “Data Structures & Algorithms” questions aren't really relevant for the work we do on the job. Occasionally, however, you might run into these sorts of problems.

In this challenge, we're going to solve a problem from a site called Project Euler.

Project Euler is a list of math-focused programming challenges. They're intended primarily for people with a mathematics background. Specifically, we're going to do a modified version of Problem 5.

Here's the prompt:

/*
Create a function that takes two parameters, `rangeStart` and `rangeEnd`. The goal is to calculate the smallest possible value which is evenly divisible by all of the numbers between `rangeStart` and `rangeEnd` (inclusive).
For example:
smallestMultiple(1, 4);
→ 12
The answer is 12 because that's the smallest number that can be evenly divisible by 1, 2, 3, and 4:
12 ÷ 1 = 12
12 ÷ 2 = 6
12 ÷ 3 = 4
12 ÷ 4 = 3

Difficulty

Honestly, I'm not sure! It's a very different problem from the sorts of things we cover in the course. I'd say it's a “medium” difficulty problem if you're comfortable with JavaScript, and have some experience with math.

Rules

  • This playground comes with lodash installed, and you're also given the range function in a local /utils.js file. Aside from this, no third-party packages are allowed.
  • Feel free to google math questions.

Playground

In the playground below, you'll find a mini test app, similar to the one used for FizzBuzz.

The expected output for the provided test case is 2520.

For questions like these, there's often a focus on performance / efficiency, so if you're able to solve this problem, you should also consider any optimizations.

Code Playground

/*
Create a function that takes two parameters, `rangeStart` and `rangeEnd`. The goal is to calculate the smallest possible value which is evenly divisible by all of the numbers between `rangeStart` and `rangeEnd` (inclusive).

smallestMultiple(1, 10);
→ 2520
*/

function smallestMultiple(rangeStart, rangeEnd) {
// TODO
}

export default smallestMultiple;

My attempt